var sumstar=0;
$(function () {

    /**
     *-----------cp
     * 首页加载默认加载全部父级类型，加载全部城市
     */
    selectBigType();
    selectProvinceList();
    $("#typeList").change(function(){
        var id=$("#typeList option:selected").val();
        //父级类型改变，子级类型也跟着改变
        selectSmallTypeList(id);
    });
    /**
     *-----------cp
     * 首页加载默认加载全部城市
     */
    $("#provinceList").change(function(){
        var id=$("#provinceList option:selected").val();
        //省份改变，市级也改变
        selectSmallCityList(id);
    });




   /*星星图标按钮事件*/
    $(".img").click(function () {
        var id=$(this).attr("id");
        if (id==1){
            $("#xingji img:nth-of-type(1)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(2)").attr("src","/product_img/logo/star-off.png");
            $("#xingji img:nth-of-type(3)").attr("src","/product_img/logo/star-off.png");
            $("#xingji img:nth-of-type(4)").attr("src","/product_img/logo/star-off.png");
            $("#xingji img:nth-of-type(5)").attr("src","/product_img/logo/star-off.png");
            $("#star").val(1);

        }
        if (id==2){
            $("#xingji img:nth-of-type(1)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(2)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(3)").attr("src","/product_img/logo/star-off.png");
            $("#xingji img:nth-of-type(4)").attr("src","/product_img/logo/star-off.png");
            $("#xingji img:nth-of-type(5)").attr("src","/product_img/logo/star-off.png");
            $("#star").val(2);
        }
        if (id==3){
            $("#xingji img:nth-of-type(1)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(2)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(3)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(4)").attr("src","/product_img/logo/star-off.png");
            $("#xingji img:nth-of-type(5)").attr("src","/product_img/logo/star-off.png");
            $("#star").val(3);
        }
        if (id==4){
            $("#xingji img:nth-of-type(1)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(2)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(3)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(4)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(5)").attr("src","/product_img/logo/star-off.png");
            $("#star").val(4);
        }
        if (id==5){
            $("#xingji img:nth-of-type(1)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(2)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(3)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(4)").attr("src","/product_img/logo/star-on.png");
            $("#xingji img:nth-of-type(5)").attr("src","/product_img/logo/star-on.png");
            $("#star").val(5);
        }
    });



});


//查询所有父级类型
function selectBigType(){
    var fatherTypeId=$("#fatherTypeId").text();
    $.getJSON("/showtype/father","fatherId=0",function(data){
        $("#typeList").html("<option value='0'>请选择类型名称</option>");
        $.each(data,function(i,e){
            if(e.showTypeId==fatherTypeId){
                $("#typeList").append("<option value='"+e.showTypeId+"' selected>"+e.typeName+"</option>");
            }else{
                $("#typeList").append("<option value='"+e.showTypeId+"'>"+e.typeName+"</option>");
            }

        });
    });
}

//根据父级类型ID查询子类型
function selectSmallTypeList(id){
    var childTypeId=$("#childTypeId").text();
    $.getJSON("/showtype/father","fatherId="+id,function(data){
        $("#smallTypeList").html("<option value='0'>请选择子类名称</option>");
        $.each(data,function(i,e){
            if(childTypeId==e.showTypeId){
                $("#smallTypeList").append("<option value='"+e.showTypeId+"' selected>"+e.typeName+"</option>");
            }else{
                $("#smallTypeList").append("<option value='"+e.showTypeId+"'>"+e.typeName+"</option>");
            }

        });
    });
}


//查询所有省会
function selectProvinceList(){
    var providerId=$("#providerId").text();
    $.getJSON("/city/hasFatherId","fatherId=0",function(data){
        $("#provinceList").html("<option value='0'>请选择省会名称</option>");
        $.each(data,function(i,e){
            if(providerId==e.cityId){
                $("#provinceList").append("<option value='"+e.cityId+"' selected>"+e.cityName+"</option>");
            }else{
                $("#provinceList").append("<option value='"+e.cityId+"'>"+e.cityName+"</option>");
            }

        });
    });
}

//根据省会查询城市
function selectSmallCityList(id){
  /*  alert(id+" 省份Id");*/
    var cityId=$("#cityId").text();
   /* alert(cityId+" cityId");*/
    $.getJSON("/city/hasFatherId","fatherId="+id,function(data){
        $("#cityList").html("<option value='0'>请选择城市名称</option>");
        $.each(data,function(i,e){
            if(cityId==e.cityId){
                $("#cityList").append("<option value='"+e.cityId+"' selected>"+e.cityName+"</option>");
            }else{
                $("#cityList").append("<option value='"+e.cityId+"'>"+e.cityName+"</option>");
            }

        });
    });
}

